import org.hibernate.engine.NamedQueryDefinition;

import java.net.URL;
import java.net.MalformedURLException;
import java.io.FileNotFoundException;
import java.util.*;
import java.sql.SQLException;

import com.abcgroup.hyppo.loader.IHibernateLoader;
import com.abcgroup.hyppo.loader.URLFileLoader;
import com.abcgroup.hyppo.jdbc.IConnectionProvider;
import com.abcgroup.hyppo.jdbc.SimpleConnectionProvider;
import com.abcgroup.hyppo.tools.IHQLExecutor;
import com.abcgroup.hyppo.tools.SimpleHQLExecutor;

public class A {

    public static void main(String[] args) throws MalformedURLException, FileNotFoundException, ClassNotFoundException, SQLException {

        IHibernateLoader ll = new URLFileLoader();
        ll.init(new URL[]{new URL("file:///C:\\Documents and Settings\\rzubairov\\.m2\\repository\\com\\betfair\\pqb\\core\\1.1.4\\core-1.1.4.jar")}, Thread.currentThread().getContextClassLoader());
        Thread.currentThread().setContextClassLoader(ll.initClassLoader());

        List<String> f = ll.getAvailableConfigs();
        for (String s : f) {
            System.err.println("==>?" + s);
        }

        ll.configureHibernate(f);
        ll.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect")
                .setProperty("hibernate.show_sql", "true")
                .setProperty("hibernate.connection.autocommit", "false");

        Class.forName("oracle.jdbc.driver.OracleDriver");

        IConnectionProvider cp = new SimpleConnectionProvider("jdbc:oracle:thin:@localhost:1521:XE", "pqb", "pqb");

        IHQLExecutor exec = new SimpleHQLExecutor(cp, ll);

        long st = 1219942200034l;
        long period = 1000 * 60 * 60;
        long day = st / period;
        long time = day * period;

        Map<String, Object> pp = new HashMap<String, Object>();
        pp.put("startTime", new Date(time - period));
        pp.put("endTime", new Date(time));
        List res = (List) exec.executeHQL("getFTFForPeriodOrderedMarket", pp);

        for (Object re : res) {
            System.out.println(" " + re);
        }

//        Object obj = exec.executeHQL("from Market m");
//
//        System.err.println(" " + obj.toString());
//
//        obj = exec.executeNamedHQL("allLangs");
//
//        System.err.println(" " + obj.toString());
//
//        Set<String> gg = ll.getAllNamedQueries();
//        for (String s : gg) {
//            System.err.println("NQ>" + s);
//
//            NamedQueryDefinition qd = ll.getQueryDefinition(s);
//            System.err.println("NQQ>" + qd);
//
//            Map qdpt = qd.getParameterTypes();
//            if (qdpt != null) {
//                for (Object o : qdpt.keySet()) {
//                    System.err.println("NQQ PD>> " + o + "=>" + qdpt.get(o));
//                }
//            }
//        }

//            setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect").
//    setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver").
//    setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:mydatabase").
//    setProperty("hibernate.connection.username", "sa").
//    setProperty("hibernate.connection.password", "").
//    setProperty("hibernate.connection.pool_size", "1").
//    setProperty("hibernate.connection.autocommit", "true").
//    setProperty("hibernate.show_sql", "true")
    }

}
